Made cwd setting in process builder optional
authorMarvin Löbel <loebel.marvin@gmail.com>
Wed, 28 Oct 2015 09:17:32 +0000 (10:17 +0100)
committerMarvin Löbel <loebel.marvin@gmail.com>
Wed, 28 Oct 2015 11:15:37 +0000 (12:15 +0100)
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/engine.rs
src/cargo/util/process_builder.rs
src/cargo/util/rustc.rs
src/cargo/util/vcs.rs

index caf5301d0dbb060a35a853b6240918a6516174c1..086d2782a5ffeaf528fe1ed5845189b37d7ff246 100644 (file)
@@ -100,7 +100,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     /// specified as well as the exe suffix
     fn filename_parts(target: Option<&str>, cfg: &Config)
                       -> CargoResult<(Option<(String, String)>, String)> {
-        let mut process = try!(util::process(cfg.rustc(), cfg.cwd()));
+        let mut process = util::process(cfg.rustc());
         process.arg("-")
                .arg("--crate-name").arg("_")
                .arg("--crate-type").arg("dylib")
index 2ce00296284b1c26666eb2a1c04f86eeef137389..9b5a3194326e4583bbb19a4e447574ff816132dd 100644 (file)
@@ -39,12 +39,16 @@ impl CommandPrototype {
     pub fn new(ty: CommandType, config: &Config)
                -> CargoResult<CommandPrototype> {
         Ok(CommandPrototype {
-            builder: try!(match ty {
-                CommandType::Rustc => process(config.rustc(), config.cwd()),
-                CommandType::Rustdoc => process(config.rustdoc(), config.cwd()),
-                CommandType::Target(ref s) |
-                CommandType::Host(ref s) => process(s, config.cwd()),
-            }),
+            builder: {
+                let mut p = match ty {
+                    CommandType::Rustc => process(config.rustc()),
+                    CommandType::Rustdoc => process(config.rustdoc()),
+                    CommandType::Target(ref s) |
+                    CommandType::Host(ref s) => process(s),
+                };
+                p.cwd(config.cwd());
+                p
+            },
             ty: ty,
         })
     }
@@ -73,7 +77,7 @@ impl CommandPrototype {
     }
 
     pub fn get_args(&self) -> &[OsString] { self.builder.get_args() }
-    pub fn get_cwd(&self) -> &Path { self.builder.get_cwd() }
+    pub fn get_cwd(&self) -> Option<&Path> { self.builder.get_cwd() }
 
     pub fn get_env(&self, var: &str) -> Option<OsString> {
         self.builder.get_env(var)
index 08003de696c391a25965219d6dcb6cfe38e6fe1e..d86df727fa3b9afd10899f1981791a0605334945 100644 (file)
@@ -5,7 +5,7 @@ use std::fmt;
 use std::path::Path;
 use std::process::{Command, Output};
 
-use util::{CargoResult, ProcessError, process_error};
+use util::{ProcessError, process_error};
 use util::shell_escape::escape;
 
 #[derive(Clone, PartialEq, Debug)]
@@ -13,7 +13,7 @@ pub struct ProcessBuilder {
     program: OsString,
     args: Vec<OsString>,
     env: HashMap<String, Option<OsString>>,
-    cwd: OsString,
+    cwd: Option<OsString>,
 }
 
 impl fmt::Display for ProcessBuilder {
@@ -42,7 +42,7 @@ impl ProcessBuilder {
     }
 
     pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder {
-        self.cwd = path.as_ref().to_os_string();
+        self.cwd = Some(path.as_ref().to_os_string());
         self
     }
 
@@ -60,8 +60,9 @@ impl ProcessBuilder {
     pub fn get_args(&self) -> &[OsString] {
         &self.args
     }
-    pub fn get_cwd(&self) -> &Path {
-        Path::new(&self.cwd)
+
+    pub fn get_cwd(&self) -> Option<&Path> {
+        self.cwd.as_ref().map(Path::new)
     }
 
     pub fn get_env(&self, var: &str) -> Option<OsString> {
@@ -108,7 +109,9 @@ impl ProcessBuilder {
 
     pub fn build_command(&self) -> Command {
         let mut command = Command::new(&self.program);
-        command.current_dir(&self.get_cwd());
+        if let Some(cwd) = self.get_cwd() {
+            command.current_dir(cwd);
+        }
         for arg in self.args.iter() {
             command.arg(arg);
         }
@@ -131,11 +134,11 @@ impl ProcessBuilder {
     }
 }
 
-pub fn process<T: AsRef<OsStr>, U: AsRef<OsStr>>(cmd: T, cwd: U) -> CargoResult<ProcessBuilder> {
-    Ok(ProcessBuilder {
+pub fn process<T: AsRef<OsStr>>(cmd: T) -> ProcessBuilder {
+    ProcessBuilder {
         program: cmd.as_ref().to_os_string(),
         args: Vec::new(),
-        cwd: cwd.as_ref().to_os_string(),
+        cwd: None,
         env: HashMap::new(),
-    })
+    }
 }
index a0cb1720f461ece9d14c3df00ade1e9a7ee86b79..1ddc36db0d86bd2f9be33556ee0c48f458227db1 100644 (file)
@@ -15,8 +15,8 @@ impl Rustc {
     /// If successful this function returns a description of the compiler along
     /// with a list of its capabilities.
     pub fn new<P: AsRef<Path>>(path: P, cwd: &Path) -> CargoResult<Rustc> {
-        let mut cmd = try!(util::process(path.as_ref(), cwd));
-        cmd.arg("-vV");
+        let mut cmd = util::process(path.as_ref());
+        cmd.cwd(cwd).arg("-vV");
 
         let mut ret = Rustc::blank();
         let mut first = cmd.clone();
index cad07c53bb1d9b0b345038d4ed03d6be54d33cf4..16fc723333826b96d080916eadb1c0e803a2f343 100644 (file)
@@ -19,11 +19,11 @@ impl GitRepo {
 
 impl HgRepo {
     pub fn init(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
-        try!(try!(process("hg", cwd)).arg("init").arg(path).exec());
+        try!(process("hg").cwd(cwd).arg("init").arg(path).exec());
         return Ok(HgRepo)
     }
     pub fn discover(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
-        try!(try!(process("hg", cwd)).arg("root").cwd(path).exec_with_output());
+        try!(process("hg").cwd(cwd).arg("root").cwd(path).exec_with_output());
         return Ok(HgRepo)
     }
 }